package org.bdware.repository.webService.config;

import org.bdware.bdoa.authentication.JwtConfig;
import org.bdware.bdoa.authentication.service.JwtService;
import org.bdware.bdoa.authentication.utils.JwxUtils;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


@Configuration
public class JwtInterceptorConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(jwtInterceptor()).addPathPatterns("/**");
    }

    @Bean
    public JwtInterceptor jwtInterceptor() {
        return new JwtInterceptor();
    }

    @Bean
    public JwtConfig jwtConfig() {
        JwtConfig jwtConfig = new JwtConfig();
        //TODO init the jwtConfig
        jwtConfig.setTokenName("accessToken");
        jwtConfig.setDoi("doi");
        jwtConfig.setSource("source");
        return jwtConfig;
    }

    @Bean
    public JwtService jwtService() {
        return JwxUtils.obtainJwtService(jwtConfig());
    }
}
